import allure
import jsonpath

from utils.send_request import send_jdbc_request

@allure.step("http断言")
def http_assert(case,res):
    if case["check"]:
        ck = jsonpath.jsonpath(res.json(), case["check"])[0]
        assert ck == case["expected"]
    else:
        assert case["expected"] in res.text

# @allure.step("数据库断言")
def jdbc_assert(case):
    if case["sql_check"] and case["sql_expected"]:
        with allure.step("数据库断言"):#过了if判断才把装饰器加到步骤里面
            result = send_jdbc_request(case["sql_check"])
            assert result == case["sql_expected"]